Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pims fallback for avi loading #1161

Merged
merged 17 commits into from
Aug 26, 2023
Merged

Pims fallback for avi loading #1161

merged 17 commits into from
Aug 26, 2023

Conversation

EricThomson
Copy link
Contributor

@EricThomson EricThomson commented Aug 24, 2023

Description

This should fix the problems with loading avi in Windows. It cleans up the logic of the pims fallback branch (thanks Pat), and I worked on the subindixing bits in pims, which was also neglected. Main change is fix to caiman_.base.movies.load() and .load_iter() methods (the later is used in online methods)

Fixes #1137 #883

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Introduces no new problems with tests.

Ran tests in pims_load_testing.py

Now the cnmfe online demo notebook runs (demo_online_cnmfE.ipynb). It would be good if someone tests on linux/mac.

Copy link
Member

@pgunn pgunn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally looks good. Solid debugging/fixup work!

@@ -1331,7 +1331,7 @@ def load(file_name: Union[str, List[str]],
is3D=is3D)

elif isinstance(file_name, tuple):
print(f'**** Processing input file {file_name} as individualframes *****')
logging.debug(f'**** Processing input file {file_name} as individualframes *****')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good time to stick a space between individual and frames

# Instead we'll explicitly go with the DirectShow backend on Windows, which
# seems to have good broad codec support (if this turns out to break other users,
# we may need a more complex solution)
# We first try with OpenCV, which is very dependent on having a working backend.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did I stick the word "very" in there? If I did, my bad. Shouldn't be there.

dims[ind] = sb.shape[0]

start_frame = subindices[0][0]
if length <= 0 or width <= 0 or height <= 0: # OpenCV failure
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to do it here (not really a comment for review, per se) but I eventually intend to pull this check out into a separate function because we do it a few times in a few places

def rgb2gray(rgb):
return np.dot(rgb[..., :3], [0.299, 0.587, 0.114])

# When everything done, release the capture
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When everything is done

input_arr = np.zeros((dims[0], height, width), dtype=np.uint8)
for i, ind in enumerate(subindices[0]):
input_arr[i] = rgb2gray(pims_movie[ind]).astype(outtype)
# logging.debug(f"subindex and shape: {ind} {input_arr[i].shape}") # helpful when mc debugging deep in weeds, otherwise overkill
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove before commit?

@@ -1982,7 +2026,7 @@ def from_zip_file_to_movie(zipfile_name: str, start_end: Tuple = None) -> Any:
mov[counter] = np.array(Image.open(file))

if counter % 100 == 0:
print([counter, idx])
logging.debug([counter, idx])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's clean this up a bit (not your fault, but since we're touching it); passing raw arrays to printing function means they're going to show up raw and ugly.

1 if subindices.step is None else subindices.step)
t = 0
for ind in subindices:
# an abomination reading frames until it hits the desired frame
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure we want to use this wording

1 if subindices.step is None else subindices.step)
for ind in subindices:
frame = rgb2gray(pims_movie[ind])
# debug.logging(f"t, ind and frame shape: {ind} - {frame.shape}") # for extremely in the weeds debugging
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to leave this in?

@@ -78,7 +107,7 @@
"source": [
"# motion correction parameters\n",
"motion_correct = True # flag for performing motion correction\n",
"pw_rigid = False # flag for performing piecewise-rigid motion correction (otherwise just rigid)\n",
"pw_rigid = True # flag for performing piecewise-rigid motion correction (otherwise just rigid)\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to change this (and in this diff) or was this just for debugging??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good eye that was for debugging. I'll switch it back

@@ -336,7 +391,7 @@
"gSig = (10//ds_factor, 10//ds_factor) # expected half size of neurons\n",
"gSiz = (22//ds_factor, 22//ds_factor)\n",
"sniper_mode = False # flag using a CNN to detect new neurons (o/w space correlation is used)\n",
"init_batch = 300 # number of frames for initialization (presumably from the first file)\n",
"init_batch = 200 # number of frames for initialization (presumably from the first file)\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same with these other notebook changes

@@ -291,7 +348,7 @@
"metadata": {},
"outputs": [],
"source": [
"cnm.estimates.play_movie(images, magnification=0.75, include_bck=False)"
"cnm.estimates.play_movie(images, magnification=0.75, include_bck=False);"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

semicolons are a bit unusual in python

@@ -3076,6 +3076,9 @@ def tile_and_correct_wrapper(params):
extension = extension.lower()
shift_info = []

print("In tile and correct wrapper about to call load with subidxs")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These messages are noisy when run in the notebook

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Cutting errant debugging msg.

" magnification=1,\n",
" gain=0.6,\n",
" plot_text=True,\n",
" do_loop=True)\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're going to default to looping, we should tell the user that they shouldn't keep waiting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point I'll cut that.

"cell_type": "markdown",
"metadata": {},
"source": [
"Inspect the summary images so you can set parameters in the following section."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cell was not commited pre-run?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was not executed, I mean

@@ -251,6 +301,15 @@
"t1 += time()"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more clever than it is legible

@pgunn pgunn merged commit f3326c2 into dev Aug 26, 2023
@pgunn pgunn deleted the dev_load_pims_fallback branch March 5, 2024 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants